<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="Content-Type" content="text/html;  charset=utf-8" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>美食推-餐厅编辑</title>
<link href="/admin/style/user/admin.css" type="text/css" rel="stylesheet" media="screen" />
<script type="text/javascript" src="http://www.sinaimg.cn/cj/dfz/js/base_v_0.1.js" charset="utf-8"></script> 
<script language="javascript" type="text/javascript" src="/admin/js/My97DatePicker/WdatePicker.js"></script>
<script language="javascript" type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="/admin/js/jquery.form.js" charset="utf-8"></script>
<style type="text/css">
.rstrt_span{display:inline-block;border:1px solid #ccc;background:#eee;padding:0 15px;line-height:28px;font-size:14px}

.down {background:url(/admin/images/sort_dn.gif) no-repeat right 0;padding-right:18px;}
.up {background:url(/admin/images/sort_up.gif) no-repeat right 0;padding-right:18px;}
.kw{background:#ddd;color:#999;}
</style>

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
/**
 * map初始化
 * @param address 搜索地点
 * @author zhanghuan at 2012/06/15
 */
function initialize(address) 
{
	geocoder = new google.maps.Geocoder();
	// 选择经纬度，默认为编辑餐厅所在位置，否则暂定为北京
	{%if $g_show.data.rstrt_info.RstrtOnMapNum%}
		var latlng = new google.maps.LatLng({%$g_show.data.rstrt_info.map.lat%}, {%$g_show.data.rstrt_info.map.lng%});
	{%else%}
		var latlng = new google.maps.LatLng(39.9, 116.3);
	{%/if%}
	
	var myOptions = {
		zoom: 10,
    	center: latlng,
    	panControl: true,//启用/停用平移控件
    	zoomControl: true,//启用/停用缩放控件
    	mapTypeControl: true,//启用/停用“地图类型”控件
    	scaleControl: true,//启用/停用“比例”控件
    	streetViewControl: true,//控件包含一个街景小人图标，将该图标拖动到地图上即可启用 Street View。该控件默认显示在地图的左上角。
    	overviewMapControl: true, //启用/停用总览图控件
    	mapTypeId: google.maps.MapTypeId.ROADMAP
  	}
    map = new google.maps.Map(document.getElementById("map"), myOptions);
    
	// 设置地图标记及经纬度提示
	var marker = new google.maps.Marker({
		position: map.getCenter(),
		map: map,
		title: map.getCenter().toString()
		});  
	google.maps.event.addListener(marker, 'click', function() {}); 
	
	// 侦听click事件
    google.maps.event.addListener(map, 'click', function(event) {
        placeMarker(event.latLng);
    });
	
	// 选择经纬度，默认为各站点城市
    {%if $g_show.data.rstrt_info.RstrtOnMapNum%}
    {%else%}
	    if (("undefined" == typeof address))
		{
			var addr = '{%if $g_show.args.city%}{%$g_show.args.city%}{%else%}北京{%/if%}';
			codeAddress(addr);
		}
    {%/if%}
	
}
   
/**
 * 事件定位
 * @param address 定位地点
 * @author zhanghuan at 2012/06/15
 */
function placeMarker(location) {
	var marker = new google.maps.Marker({
		position: location, 
		map: map,
		title: location.toString()
	});

	map.setCenter(location);
	location = location.toString();
	var p_tmp = location.replace('(',''); 
	location = p_tmp.replace(')',''); 
	location = location.replace(' ',''); 
	var arrpxy = location.split(",");
	document.getElementById('lat').value = arrpxy[0];
	document.getElementById('lang').value = arrpxy[1];
}

/**
 * 地点搜索
 * @param address 搜索地点
 * @author zhanghuan at 2012/06/15
 */
function codeAddress(address) {
	if(address == '')
	{
		alert('请输入正确的地址');
		return false;
	}
	OpenMap(address);
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map, 
            position: results[0].geometry.location,
            title:results[0].geometry.location.toString()
        });
      } else {
        alert("地理编码失败为以下的原因: " + status);
      }
    });
}
</script>

</head>
<body>
	<div class="sec-title">
		<h3 class="title"><a href="#">美食推</a><i>&gt;</i>餐厅编辑</h3>
	</div>
	<div style="margin-top: 15px;">
		<div id="form2">
		<table>
			<tr>
				<td>* 餐厅名称：</td><td>
				<input type=hidden value="{%if $g_show.args.RstrtPID%}{%$g_show.args.RstrtPID%}{%else%}{%$g_show.data.rstrt_info.RstrtID%}{%/if%}" name="RstrtPID" id="RstrtPID" />
				<input type=text value="{%$g_show.data.rstrt_info.RstrtName%}" name="RstrtName" id="RstrtName" />
				{%if $g_show.data.rstrt_info.RstrtChain%}
				连锁店名称：<input type=text value="{%$g_show.data.rstrt_info.RstrtChainName%}" name="RstrtChainName" id="RstrtChainName" />
				{%/if%}
				</td>
				<td>微博UID：</td><td><input type=text value="{%$g_show.data.rstrt_info.RstrtWeiboID%}" name="RstrtWeiboID" id="RstrtWeiboID" /></td>
			</tr>
			<tr>
				<td>上传图片</td>
				<td class="td_right">
					<form action="rstrt_edit_post.php?rstrt_id={%$g_show.data.rstrt_info.RstrtID%}" method="post" id="cover_form" enctype="multipart/form-data">
					<input type=file name="file1"/>
					<input type=submit value="上传" />
					</form>
					<input type=text id="RstrtPic" value="{%$g_show.data.rstrt_info.RstrtPic%}" style="display:none;" />
				</td>
			</tr>
			<tr>
				<td></td>
				<td class="td_right">
					<img src="{%$g_show.data.rstrt_info.RstrtPic%}" id="RstrtPic2" width=250 />
					<br />
				（建议上传最佳像素尺寸250X180，格式jpg。）
				</td>
			</tr>
			<tr>
				<td>别名：</td><td colspan=3><input type=text value="{%$g_show.data.rstrt_info.cname%}" name="cname" id="cname" />
				最多填5个，以半角逗号隔开
				</td>
			</tr>
			<tr>
				<td>* 菜系：</td><td colspan=3>
						{%foreach from=$g_show.style key=i item=val name=loop %}
						<input type='checkbox' value="{%$val.name%}" name="RstrtFlavorByAddr[]" id="RstrtFlavorByAddr[]" {%if $val.status%}checked="checked"{%/if%} />{%$val.name%}
						{%if ($smarty.foreach.loop.index+1) % 10 eq 0%}
						<br />
						{%/if%}
						{%/foreach%}
				</td>
			</tr>
<!-- 			<tr>
				<td>* 风味：</td><td colspan=3>
						{%foreach from=$g_show.flavor key=i item=val name=loop %}
						<input type='checkbox' value="{%$val.name%}" name="RstrtFlavorByType[]" id="RstrtFlavorByType[]" {%if $val.status%}checked="checked"{%/if%} />{%$val.name%}
						{%if ($smarty.foreach.loop.index+1) % 10 eq 0%}
						<br />
						{%/if%}
						{%/foreach%}
				</td>
			</tr> -->
			<tr>
				<td>本店简介：</td><td colspan=3>
					<textarea rows="8" cols="48" name="RstrtInfo" id="RstrtInfo">{%$g_show.data.rstrt_info.RstrtInfo%}</textarea>
					
				</td>
			</tr>
			<tr>
				<td>推荐菜品：</td><td colspan=3><input size="40" type=text value="{%$g_show.data.rstrt_info.RstrtFood%}" name="RstrtFood" id="RstrtFood" />
				多个菜名以半角逗号隔开
				</td>
			</tr>
			<tr>
				<td>特色服务：</td><td colspan=3>
					{%foreach from=$g_show.rstrt_service key=i item=val name=loop %}
						<input type='checkbox' value="{%$val.name%}" name="rstrt_service[]" id="rstrt_service[]" {%if $val.status%}checked="checked"{%/if%} />{%$val.name%}
						{%if ($smarty.foreach.loop.index+1) % 10 eq 0%}
						<br />
						{%/if%}
					{%/foreach%}
				</td>
			</tr>
			<tr>
				<td>环境：</td><td colspan=3>
					{%foreach from=$g_show.rstrt_env key=i item=val name=loop %}
						<input type='checkbox' value="{%$val.name%}" name="rstrt_env[]" id="rstrt_env[]" {%if $val.status%}checked="checked"{%/if%} />{%$val.name%}
						{%if ($smarty.foreach.loop.index+1) % 10 eq 0%}
						<br />
						{%/if%}
					{%/foreach%}
				</td>
			</tr>
			<tr>
				<td>人均消费：</td><td colspan=3>
					<input name="RstrtPayAverage" id="RstrtPayAverage" value="{%$g_show.data.rstrt_info.RstrtPayAverage%}" />
				</td>
			</tr>
			<tr>
				<td>开业时间：</td><td colspan=3>
					<input name="RstrtOpenTime" id="RstrtOpenTime" value='{%if $g_show.data.rstrt_info.RstrtOpenTime%}{%$g_show.data.rstrt_info.RstrtOpenTime%}{%else%}00:00:00{%/if%}' class="Wdate" type="text" onFocus="WdatePicker({dateFmt:'HH:mm:ss'})"  size="10" />
					结业时间：
					<input name="RstrtCloseTime" id="RstrtCloseTime" value='{%if $g_show.data.rstrt_info.RstrtCloseTime%}{%$g_show.data.rstrt_info.RstrtCloseTime%}{%else%}00:00:00{%/if%}' class="Wdate" type="text" onFocus="WdatePicker({dateFmt:'HH:mm:ss'})"  size="10" />
					* 联系电话：<input type=text name="RstrtTel" id="RstrtTel" value="{%$g_show.data.rstrt_info.RstrtTel%}" />
				</td>
			</tr>
			<tr>
				<td>* 餐厅地址：</td><td colspan=3>
					<select name="RstrtCity" id="RstrtCity" onchange="get_region(this.value);" >
						<option value='-1'>市</option>
						{%foreach from=$g_show.city key=i item=val %}
						<option value="{%$val.area_id%}">{%$val.area_name%}</option>
						{%/foreach%}
					</select>
					<select name="RstrtRegion" id="RstrtRegion" onchange="get_area(this.value);">
						<option value='-1'>区</option>
					</select>
					<select name="RstrtArea" id="RstrtArea">
						<option value='-1'>商圈</option>
						{%foreach from=$g_show.area key=i item=val name=loop %}
						<option value='{%$val.name%}' {%if $val.status%}selected="selected"{%/if%}>{%$val.name%}</option>
						{%/foreach%}
						
					</select>
					<br />
					<input name="RstrtAddr" id="RstrtAddr" size=100 value='{%$g_show.data.rstrt_info.RstrtAddr%}'/>
				</td>
			</tr>
			<tr>
				<td></td><td colspan=3 id="map_td">
					
					<a href="###" onclick="ChangeMapFun(this)">点击选择经纬度</a>
					经度：<input type="text" id="lang" name="lang" value="{%$g_show.data.rstrt_info.map.lng%}"/>
					纬度：<input type="text" id="lat" name="lat" value="{%$g_show.data.rstrt_info.map.lat%}"/>
					检索地址：<input type="text" id="address" name="address"/>
					<input type="button" name="search" id="search" value="查找" onclick="codeAddress($('#address').val());"/>
					
				</td>
			</tr>
			<tr>
				<td>交通路线：</td><td colspan=3>
					<input type=text size="56" id="RstrtTraffic" name="RstrtTraffic" value="{%$g_show.data.rstrt_info.RstrtTraffic%}" />
				</td>
			</tr>
			<tr>
				<td></td><td colspan=3>
				{%if $g_show.args.RstrtPID%}
					<a href=### id="chain_add">+ 继续添加分店</a>
				{%else%}
					<a href=### id="chain_add">+ 添加分店</a>
				{%/if%}
					
				</td>
			</tr>
			<tr>
				<td></td><td colspan=3>
					
				</td>
			</tr>
			<tr>
				<td></td><td colspan=3>
					<input type="button" onclick="rstrt_submit();" value="提交" />
					&nbsp;&nbsp;&nbsp;
					<input type="button" value="重置" />
				</td>
			</tr>
			
			
		</table>
		</div>
	</div>


	<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</body>
<script>

// 城市/区/商圈处理
function get_region(val)
{
	var url = "ajax_eat_area.php?id="+val+"&type=region";
	$.getJSON(url, function(json) {
		$("#RstrtRegion").html("<option value='-1'>区</option>");
		$.each(json.data, function(i, n) {
			$("#RstrtRegion").append($("<option value='"+n.area_id+"' >"+n.area_name+"</option>"));
		});
	});
}

/*
function get_area(val)
{
	var url = "ajax_eat_area.php?id="+val+"&type=area";
	$.getJSON(url, function(json) {
		$("#RstrtArea").html("<option value='-1'>商圈</option>");
		$.each(json.data, function(i, n) {
			$("#RstrtArea").append($("<option value='"+n.id+"' >"+n.area_name+"</option>"));
		});
	});
}
*/

//打开地图选择页面
var map_status = 1;
function ChangeMapFun(obj)
{
	if(map_status == 1)
	{
		OpenMap();
		map_status = 0;
		$(obj).html("关闭地图");
	}
	else
	{
		CloseMap();
		map_status = 1;
		$(obj).html("点击选择经纬度");
	}
}
/**
 * 打开地图
 * @param address 搜索地点
 */
function OpenMap(address)
{
	$("#map_td").append("<div id='map'></div>");
	$("#map").height("644px");
	$("#map").width("864px");
	initialize(address);
}
/**
 * 关闭地图
 */
function CloseMap()
{
	$("#map").remove();
}

//添加分店
$("#chain_add").bind("click",function(){
	$.post("rstrt_edit_post.php?rstrt_id={%$g_show.data.rstrt_info.RstrtID%}&Chain=1",
	$("input").serialize()+"&"+$("select").serialize(),
	function(data)
	{
		if (data.error == 1)
		{
			alert(data.errmsg);
		}
		else
		{
			alert("操作成功！");
			location.href = data.url;
		}
	},'json');
})

//添加或更新
function rstrt_submit()
{
	$.post("rstrt_edit_post.php?rstrt_id={%$g_show.data.rstrt_info.RstrtID%}",
	"RstrtPic="+$("#RstrtPic").val()+"&"+
	$("input").serialize()+"&"+$("select").serialize()+"&"+$("textarea").serialize(),
	function(data)
	{
		is_chain = '{%$g_show.args.chain_id%}';
		if(is_chain>0)
		{
			alert("操作成功！");
			location.href = "rstrt_chain.php?rstrt_id="+is_chain;
			return;
		}
		if (data.error == 1)
		{
			alert(data.errmsg);
		}
		else
		{
			alert("操作成功！");
			location.href = data.url;
		}
	},'json');
}

//图片上传
$(function(){
	$("#cover_form").submit(function(){
		$(this).ajaxSubmit(function(json_data){
			json_data = json_data.replace("<pre>","");
			json_data = json_data.replace("</pre>","");
			json_data = eval("("+json_data+")");
			if (json_data.error == 1)
			{
				alert(json_data['errmsg']);
			}
			else
			{
				$("#RstrtPic").val(json_data.data);
				$("#RstrtPic2").attr('src',json_data.data);
			}
			
		},'json')
		return false;
	})
})

</script>
</html>
